#!/usr/bin/env bash
#  vim:ts=4:sts=4:sw=4:et
#
#  Author: Hari Sekhon
#  Date: 2016-12-17 19:47:36 +0000 (Sat, 17 Dec 2016)
#
#  https://github.com/HariSekhon/Dockerfiles
#
#  License: see accompanying Hari Sekhon LICENSE file
#
#  If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
#  https://www.linkedin.com/in/HariSekhon
#

set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

tag="latest"

IMAGE_NAME="${IMAGE_NAME:-$(awk -F= '/^[[:space:]]*REPO[[:space:]]*:*=/{gsub (" ", "", $2); print $2}' "$srcdir/../Makefile")}"
DOCKER_REPO="${DOCKER_REPO:-${IMAGE_NAME/:*}}"

echo "tagging $IMAGE_NAME as $DOCKER_REPO:$tag"
docker tag "$IMAGE_NAME" "$DOCKER_REPO:$tag"
echo "pushing $DOCKER_REPO:$tag"
docker push "$DOCKER_REPO:$tag"
